﻿(function($){
	$.Menu = {};
	
	$.Menu = {
		SmallImageModify : null,
		ViewImageModify : null,
		Init : function() {
			$("#m_MenuAdd input.m_btnSmallImage").click(function() {
				$.manager.fileopen(2, "$.Menu.SmallImage_Add" );
			});
			
			$("#m_MenuAdd input.m_btnLargeImage").click(function() {
				$.manager.fileopen(3, "$.Menu.LargeImage_Add" );
			});
			
			$("#m_MenuAdd input.m_MenuAdd").click(function() {
				$.Menu.Create();
			});
			
			$("#selCategory").change(function() {
				$.Menu.GetList();
			});
			
			$.Menu.GetList();
		},
		
		Create : function() {
			var CategoryNo = $("#selCategory").val();
			var KorName = $("#m_MenuAdd input.m_KorName").val();
			var EngName = $("#m_MenuAdd input.m_EngName").val();
			var Desc = $("#m_MenuAdd textarea.m_Desc").val();
			var SmallImage = $("#m_MenuAdd input.m_SmallImage").val();
			var LargeName = $("#m_MenuAdd input.m_LargeImage").val();
			
			
			$("#m_MenuAdd").ajaxNet(
			"/manager/menu/menuMethod.aspx?_vb=Create",
			{
				"CategoryNo" : CategoryNo,
				"EngName" : EngName,
				"KorName" : KorName,
				"Desc" : Desc,
				"SmallImageURL" : SmallImage,
				"LargeImageURL" : LargeName
			}, function(results, context)
			{
				alert('등록되었습니다.');
				location.href = location.href;
			});
		},
		
		Remove : function( SeqNo )
		{
			if ( confirm("정말로 삭제하시겠습니까?") )
			{
				$("#m_MenuAdd").ajaxNet(
				"/manager/menu/menuMethod.aspx?_vb=Remove",
				{
					"SeqNo" : SeqNo
				}, function(results, context)
				{
					alert('삭제 되었습니다.');
					location.href = location.href;
				});
			}
		},
		
		SetTop : function( SeqNo )
		{
			$("#m_MenuAdd").ajaxNet(
			"/manager/menu/menuMethod.aspx?_vb=SetTop",
			{
				"SeqNo" : SeqNo
			}, function(results, context)
			{
				$.Menu.GetList();
			});
		},
		
		GetList : function()
		{
			var CategoryNo = $("#selCategory").val();
			 $("#m_MenuList").ajaxNet(
			"/manager/menu/menuMethod.aspx?_vb=GetList",
			{
				"CategoryNo" : CategoryNo,
				"PageNo" : 1,
				"PageSize" : 50
			}, function(results, context)
			{
				$("#m_MenuList").html( results );
				$("#m_MenuList input.m_BtModify").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$("#m_MenuList tr.m_MenuInput_" + data.SeqNo ).show();
					$("#m_MenuList tr.m_MenuInfo_" + data.SeqNo ).hide();
				});
				
				$("#m_MenuList input.m_BtRemove").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$.Menu.Remove( data.SeqNo );
				});
				
				$("#m_MenuList input.m_BtTop").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$.Menu.SetTop( data.SeqNo );
				});
				
				$("#m_MenuList input.m_btnSmallImage").click(function() {
					var $tr = $(this).closest("tr");
					$.Menu.SmallImageModify = $tr.find("input.m_SmallImage"); 
					$.manager.fileopen(2, "$.Menu.SmallImageList_Add" );
				});
				
				$("#m_MenuList input.m_btnViewImage").click(function() {
					var $tr = $(this).closest("tr");
					$.Menu.ViewImageModify = $tr.find("input.m_ViewImage"); 
					$.manager.fileopen(3, "$.Menu.LargeImageList_Add" );
				});
				
				$("#m_MenuList input.m_BtModifyConfirm").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$.Menu.Modify( data.SeqNo );
				});
				
				
				$("#m_MenuList input.m_BtModifyCancel").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$("#m_MenuList tr.m_MenuInput_" + data.SeqNo ).hide();
					$("#m_MenuList tr.m_MenuInfo_" + data.SeqNo ).show();
				});
			});
		},
		
		Modify : function( SeqNo ) {
			var CategoryNo = $("#selCategory").val();
			var KorName = $("#m_MenuList tr.m_MenuInput_" + SeqNo ).find("input.m_KorName").val();
			var EngName = $("#m_MenuList tr.m_MenuInput_" + SeqNo ).find("input.m_EngName").val();
			var Desc = $("#m_MenuList tr.m_MenuInput_" + SeqNo ).find("textarea.m_Desc").val();
			var SmallImage = $("#m_MenuList tr.m_MenuInput_" + SeqNo ).find("input.m_SmallImage").val();
			var LargeName = $("#m_MenuList tr.m_MenuInput_" + SeqNo ).find("input.m_ViewImage").val();
			
			
			$("#m_MenuAdd").ajaxNet(
			"/manager/menu/menuMethod.aspx?_vb=Modify",
			{
				"SeqNo" : SeqNo,
				"EngName" : EngName,
				"KorName" : KorName,
				"Desc" : Desc,
				"SmallImageURL" : SmallImage,
				"LargeImageURL" : LargeName
			}, function(results, context)
			{
				alert('수정되었습니다.');
				location.href = location.href;
			});
		},
		
		SmallImage_Add : function( imageurl ) {
			$("#m_MenuAdd input.m_SmallImage").val( imageurl );
		},
		
		LargeImage_Add : function( imageurl ) {
			$("#m_MenuAdd input.m_LargeImage").val( imageurl );
		},
		
		SmallImageList_Add : function( imageurl ) {
			$.Menu.SmallImageModify.val( imageurl );
		},
		
		LargeImageList_Add : function( imageurl ) {
			$.Menu.ViewImageModify.val( imageurl );
		}
	}
	
	$(function() {
		$.Menu.Init();
	});
})(jQuery);
